home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
c_dates2.arc
/
SEPARATE.ARC
/
DAYCNT.C
next >
Wrap
Text File
|
1991-01-10
|
2KB
|
55 lines
/************************************************************************/
/* *** daycnt.c *** */
/* */
/* This function returns the number of days of the specified type that */
/* exist between the two julian dates input, expressed as an signed */
/* long integer. */
/* */
/* The input values to the function, in their proper order, are: */
/* */
/* 1. the beginning julian date ( unsigned long ) */
/* */
/* 2. the ending julian date ( unsigned long ) */
/* */
/* 3. the numerical code representing the type */
/* of days to be counted ( described below ) ( unsigned int ) */
/* */
/* The following is a list of the codes used to define the */
/* type of days that are to be counted: */
/* */
/* CODE - EXPLANATION - */
/* */
/* 0 - all days */
/* */
/* 1 - all days excluding Sundays */
/* */
/* 2 - all days excluding weekends ( Saturdays and Sundays ) */
/* */
/* NOTE - input of any code not listed above will be */
/* interpreted as code 0. */
/* */
/************************************************************************/
extern int dow( unsigned long );
long daycnt( juldt1, juldt2, excl )
long juldt1, juldt2;
unsigned int excl;
{
int eff = 7 - ( excl = excl > 2 ? 0 : excl );
if ( !excl-- ) return( juldt2 - juldt1 );
if ( juldt1 > juldt2 ) return( -daycnt( juldt2, juldt1, ++excl ) );
else
{
juldt1 -= !dow( juldt1 ) + ( excl && !( dow( juldt1 ) % 6 ) );
juldt2 -= !dow( juldt2 ) + ( excl && !( dow( juldt2 ) % 6 ) );
}
return( ( juldt2 - juldt1 ) / 7 * eff +
( dow( juldt2 ) - dow( juldt1 ) + eff ) % eff );
}